package com.jgraves.WikiToSpeech;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


/** Structure for holding a list of history
 * @author johngraves
 *
 */
public class HistoryArrayAdapter extends ArrayAdapter<HistoryOption> {

	private Context c;
	private int id;
	private List<HistoryOption> files;

	public HistoryArrayAdapter(Context context, 
			int textViewResourceId,
			List<HistoryOption> objects) {
		super(context, textViewResourceId, objects);
		c = context;
		id = textViewResourceId;
		files = objects;
	}

	public HistoryOption getItem(int i)
	{
		return files.get(i);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(id, null);
		}
		final HistoryOption o = files.get(position);
		if (o != null) {
			TextView t1 = (TextView) v.findViewById(R.id.TextView01);

			if(t1!=null)
				t1.setText(o.getName());
		}
		return v;
	}
}
